//<!-- 通道收费报表 -->
export default {
  data () {
    return {
      parkNameListRow: {
        searchParams:{},
        pageNumber:1,
        total: 0,
        theadsInfo: [
          { index: 0, isShow: false, prop: 'reno', text: '序号', width: 68 },
          { index: 1, isShow: false, prop: 'm', text: '停车场', minWidth: 110 }
        ],
        tbodysInfo: []
      },
      parkNameRow:{}
    }
  },
  created () {
    
  },
  methods: {
    // 重新生成按钮
    reBuild(){
      this.$refs.myReBuildBtn.reBuild()
    },
    getDefaultParams(){//获取不能缺少的默认的参数
        let self = this;
        let searchParams = self.searchParams,
            searchList = self.searchList,
            result = {};
            var itemreportDimension,itemdateFromTo;
            for (var key in searchList) {
                if (searchList.hasOwnProperty(key)) {
                    var item = searchList[key];
                    if(item.name=='reportDimension'){
                        itemreportDimension = item;
                    }else if(item.name=='dateFromTo'){
                        itemdateFromTo = item;
                    }
                }
            }
            if(!self.searchParams.reportDimension){
                result.reportDimension = itemreportDimension.value;
            }
            if(!self.searchParams.reportDateFrom){
                result.reportDateFrom = moment(itemdateFromTo.value[0]).format('YYYY-MM-DD HH:mm:ss');
                result.reportDateTo = moment(itemdateFromTo.value[1]).format('YYYY-MM-DD HH:mm:ss');
            }
        return result;
    },
    getList () {
      let params = $.extend({}, this.searchParams, this.otherParams,this.getDefaultParams());
      this.getParkChannelChargeReportList(params);
    },
    getParkChannelChargeReportList (aparams) {//查询列表
      let self = this,
          params = {
            page: this.pageNumber,
            rp: this.pageSize
          };
      params = $.extend({}, params, aparams);

      switch (params.reportDimension) {
          case 'day':
              //params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY-MM-DD').startOf('day').format('YYYY-MM-DD HH:mm:ss');
              //params['reportDateTo'] = moment(params.reportDateTo, 'YYYY-MM-DD').endOf('day').format('YYYY-MM-DD HH:mm:ss');
              break;
          case 'month':
              params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY-MM').startOf('month').format('YYYY-MM-DD HH:mm:ss');
              params['reportDateTo'] = moment(params.reportDateTo, 'YYYY-MM').startOf('month').format('YYYY-MM-DD 00:00:00');
              break;
          case 'year':
              params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY').startOf('year').format('YYYY-MM-DD HH:mm:ss');
              params['reportDateTo'] = moment(params.reportDateTo, 'YYYY').startOf('year').format('YYYY-MM-DD 00:00:00');
              break;
          case 'custom':
              params['reportDateFrom'] = params.reportDateFrom;
              params['reportDateTo'] = params.reportDateTo;
              break;
          default:
      }
      API.report.GetParkChannelChargeReportData(params)
        .then(res => {
          let data = res.data,
              list = data.rows;
          self.tbodysInfo = list;
          self.total = data.total;
        }, err => {})
    },
    exportData(){//导出
      let self = this;
      this.showDialog("是否确认导出记录？",[],function(){
        let params = {
        };
        params = $.extend({}, params, self.searchParams, self.otherParams,self.getDefaultParams());

        switch (params.reportDimension) {
          case 'day':
              //params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY-MM-DD').startOf('day').format('YYYY-MM-DD HH:mm:ss');
              //params['reportDateTo'] = moment(params.reportDateTo, 'YYYY-MM-DD').endOf('day').format('YYYY-MM-DD HH:mm:ss');
              break;
          case 'month':
              params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY-MM').startOf('month').format('YYYY-MM-DD HH:mm:ss');
              params['reportDateTo'] = moment(params.reportDateTo, 'YYYY-MM').startOf('month').format('YYYY-MM-DD 00:00:00');
              break;
          case 'year':
              params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY').startOf('year').format('YYYY-MM-DD HH:mm:ss');
              params['reportDateTo'] = moment(params.reportDateTo, 'YYYY').startOf('year').format('YYYY-MM-DD 00:00:00');
              break;
          case 'custom':
              params['reportDateFrom'] = params.reportDateFrom;
              params['reportDateTo'] = params.reportDateTo;
              break;
          default:
        }

        self.toExportAsync('/report/channel_charge/export.do', params);
      },"温馨提示",function(){
        //取消时不操作
      });
    },
    filterMultiCheck (selectionArr) {//必须定义获取多列的方法
      let result = [];
        selectionArr.map((item)=>{
          result.push(item.id);
        });
      return result;
    },
  }
}